package com.honeybee.cloud.framework.oauth.config;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;

/**
 * @Description ResourceServer
 * @Author DELL
 * @Create 2018-12-13
 * @Since 1.0.0
 */

public abstract class OauthResourceServerConfig extends ResourceServerConfigurerAdapter {


    /**
     *         http.formLogin()
     *                 //登录页面，app用不到
     *                 //.loginPage("/authentication/login")
     *                 //登录提交action，app会用到
     *                 // 用户名登录地址
     *                 .loginProcessingUrl("/auth/token")
     *                 //成功处理器 返回Token
     *                 .successHandler(this.authenticationSuccessHandler)
     *                 //失败处理器
     *                 .failureHandler(this.authenticationFailureHandler);
     * @param http
     * @throws Exception
     */
    @Override
    public abstract void configure(HttpSecurity http) throws Exception;


    @Bean
    public OAuth2WebSecurityExpressionHandler oAuth2WebSecurityExpressionHandler(ApplicationContext applicationContext) {
        OAuth2WebSecurityExpressionHandler expressionHandler = new OAuth2WebSecurityExpressionHandler();
        expressionHandler.setApplicationContext(applicationContext);
        return expressionHandler;
    }
}
